from functools import wraps
from rest_framework.response import Response


def role_required():
    def decorator(view_func):
        @wraps(view_func)
        def _wrapped_view(self, request, *args, **kwargs):
            role = request.user.role
            print(role)
            if role == 2:
                return view_func(self, request, *args, **kwargs)
            else:
                return Response({"detail": "你还没有权限访问该页面"}, status=403)
        return _wrapped_view
    return decorator
